import { createRouter, createWebHistory } from 'vue-router'

// 导入路由组件
// 一级路由
import Layout from '@/views/Layout/index.vue'
import Login from '@/views/Login/index.vue'

// 二级路由
import Home from '@/views/Home/index.vue'
import Category from '@/views/Category/index.vue'
import SubCategory from '@/views/SubCategory/index.vue'
import Detail from '@/views/Detail/index.vue'
import ListCart from '@/views/Layout/components/ListCart.vue'
import Checkout from '@/views/Checkout/index.vue'
import Pay from '@/views/Pay/index.vue'
import PayCallback from '@/views/PayCallback/index.vue'
import Member from '@/views/Member/index.vue'

// 三级路由组件
import UserInfo from '@/views/Member/components/UserInfo.vue'
import UserOrder from '@/views/Member/components/UserOrder.vue'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  scrollBehavior() {
    return { top: 0 }
  },
  routes: [
    {
      path: '/',
      component: Layout,
      redirect: '/home',
      children: [
        {
          path: 'home',
          component: Home
        },
        {
          path: 'category/:id',
          component: Category,
        },
        {
          path: 'category/sub/:id',
          component: SubCategory,
        },
        {
          path: 'detail/:id',
          component: Detail
        },
        {
          path: 'listcart',
          component: ListCart
        },
        {
          path: 'checkout',
          component: Checkout
        },
        {
          path: 'pay',
          component: Pay
        },
        {
          path: 'paycallback',
          component: PayCallback
        },
        {
          path: 'member',
          component: Member,
          redirect: '/member/userinfo',
          children: [
            {
              path: 'userinfo',
              component: UserInfo
            },
            {
              path: 'userorder',
              component: UserOrder
            }
          ]
        },

      ]
    },
    {
      path: '/login',
      component: Login
    }
  ]
})

export default router
